from django.http import JsonResponse
from django.shortcuts import render, redirect
from workDjango import models


# 可视化部分
def show(request):
    return render(request, 'work01.html')


# 1.1.厨具销售详情可视化
def goods_sales_show(request):
    y_data = []
    x_data = []
    y2_data = []

    data = models.ProductSales.objects.all()
    # data = models.SalesDetail.objects.all()

    for i in data:
        x_data.append(i.product_name)
        y_data.append(i.sales_volume)
        y2_data.append(i.rating)

    x_list = x_data
    y_list = [
        {'name': '销量',
         'type': 'bar',  # 设置图像类别
         'data': y_data}
    ]
    y2_list = [
        {'name': '好评',
         'type': 'line',  # 设置图像类别
         'data': y2_data}
    ]
    legend = []
    result = {
        "status": True,
        "data": {
            "x_list": x_list,
            "y_list": y_list,
            "y2_list": y2_list
        }
    }
    print(result)
    return JsonResponse(result)


# 1.2.商品价格详情表，链接到厨具销售详情。
#
# # 2.不同类型商品销量可视化
# def goods_sales_type_show(request):
#     pass
#
#
# # 3.不同品牌商品可视化
# def goods_sales_brand_show(request):
#     pass
#
#
# # 4.商品好评率可视化
# def goods_sales_rate_show(request):
#     pass
